scripty2

class S2.FX.Base

Constructor

new S2.FX.Base([options])

Base calls for all effects. Subclasses need to define the update instance method for it to be useful. scripty2 currently provides one subclass implementation for effects based on DOM elements, S2.FX.Element.

Effect options

There are serveral ways the options argument can be used:

new S2.FX.Base({ duration: 3, transition: 'spring' });
new S2.FX.Base(function(){})   // shortcut for { after: function(){} }
new S2.FX.Base(3);             // shortcut for { duration: 3 }
new S2.FX.Base('slow');        // shortcut for { duration: 1 }
new S2.FX.Base('fast');        // shortcut for { duration: .1 }

The following options are recognized:

  • duration: duration in seconds, defaults to 0.2 (a fifth of a second). This speed is based on the value Mac OS X uses for interface effects.
  • transition: Function reference or String with a property name from S2.FX.Transitions. Sets the transition method for easing and other special effects.
  • before: Function to be executed before the first frame of the effect is rendered.
  • after: Function to be executed after the effect has finished.
  • beforeUpdate: Function to be executed before each frame is rendered. This function is given two parameters: the effect instance and the current position (between 0 and 1).
  • afterUpdate: Function to be executed after each frame is renedred. This function is given two parameters: the effect instance and the current position (between 0 and 1).
  • fps: The maximum number of frames per second. Ensures that no more than options.fps frames per second are rendered, even if there's enough computation resources available. This can be used to make CPU-intensive effects use fewer resources.
  • queue: Specify a S2.FX.Queue to be used for the effect.
  • position: Position within the specified queue, parallel (start immediately, default) or end (queue up until the last effect in the queue is finished)

The effect won't start immediately, it will merely be initialized. To start the effect, call S2.FX.Base#play.

Instance methods

  • cancel #

    S2.FX.Base#cancel([after]) -> undefined
    • after (Boolean) – if true, run the after method (if defined), defaults to false

    Calling cancel() immediately halts execution of the effect, and calls the teardown method if defined.

  • finish #

    S2.FX.Base#finish() -> undefined

    Immediately render the last frame and halt execution of the effect and call the teardownmethod if defined.

  • inspect #

    S2.FX.Base#inspect() -> String

    Returns the debug-oriented string representation of an effect.

  • play #

    S2.FX.Base#play([options]) -> S2.FX.Base
    • options – Effect options, see above.

    Starts playing the effect. Returns the effect.

  • render #

    S2.FX.Base#render(timestamp) -> undefined
    • timestamp (Date) – point in time, normally the current time

    Renders the effect, and calls the before/after functions when necessary. This method also switches the state of the effect from idle to running when the first frame is rendered, and from running to finished after the last frame is rendered.

  • update #

    S2.FX.Base#update() -> undefined

    The update method is called for each frame to be rendered. The implementation in S2.FX.Base simply does nothing, and is intended to be overwritten by subclasses. It is provided for cases where S2.FX.Base is instantiated directly for ad-hoc effects using the beforeUpdate and afterUpdate callbacks.